package com.google.code.p.mumu.test;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CurrentRequestClient {
    //http://www.blogjava.net/jlins-you/archive/2012/04/24/376516.html
    //可参考：ab（ApacheBench）是Apache自带的超文本传输协议(HTTP)性能测试工具
    public static void main(String[] args) {
        int count = 1000;
        CyclicBarrier cyclicBarrier = new CyclicBarrier(count);
        ExecutorService executorService = Executors.newFixedThreadPool(count);
        for (int i = 0; i < count; i++)
            executorService.execute(new CurrentRequestClient().new Task(cyclicBarrier));
        
        executorService.shutdown();
        while (!executorService.isTerminated()) {
            try {
                Thread.sleep(10);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    public class Task implements Runnable {
        private CyclicBarrier cyclicBarrier;
        
        public Task(CyclicBarrier cyclicBarrier) {
            this.cyclicBarrier = cyclicBarrier;
        }
        
        public void run() {
            try {
                // 等待所有任务准备就绪
                cyclicBarrier.await();
                // 测试内容
                // TODO
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
}
